/*
 * ULSF Sagittarius IDA
 * Copyright (C) 2012, John Pritchard, all rights reserved.
 * 
 * This program is free software: you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see
 * <http://www.gnu.org/licenses/>.
 */
package sagittarius.design;

/**
 * This fit model is scaled to a volume
 */
public class ModelHyperbolicShell
    extends AbstractModel
    implements Model.Path
{
    /**
     * Longitude parameter
     */
    public final float station;
    /**
     * Longitude parameter
     */
    public final double uniform;
    /**
     * Shell parameter
     */
    public final float sector, sectorR;
    /**
     * Area of the shell section
     */
    public final float area;
    /**
     * XY ({@link Visualization} YZ) vertices of the shell in CCW order
     * from A to B (top) and B to A (bottom).
     */
    public final float[] vertices;


    public ModelHyperbolicShell(VolumeHyperbolic volume, double station){
        super();
        this.station = (float)station;
        this.uniform = volume.uniform(station);
        this.sector = volume.model(this.uniform,station);
        this.sectorR = volume.sector(this.sector);
        this.vertices = this.generateShell(this.sector);
        this.area = fv3.math.FastArea.Area2(this.vertices);
    }


    public float[] getVerticesFor(float area, float radius){

        return this.generatePath(area);
    }
    public float getPathArea(){
        return this.area;
    }
    public float[] getPathVertices(){
        return this.vertices.clone();
    }
    public boolean isPath(){
        return true;
    }
    public boolean isHyperbolic(){
        return true;
    }
    public boolean isSectional(){
        return false;
    }
    public float getHyperbolicSector(){
        return this.sector;
    }
    public float getHyperbolicSectorRatio(){
        return this.sectorR;
    }


    /**
     * Print the vertices of the shell set, or accept an index
     * argument for one shell.
     */
    public static void main(String[] argv){
        Body body = new Body();
        VolumeHyperbolic volume = new SearsHaackHyperbolic(body,300,1000);

        if (0 < argv.length){
            final float station = Float.parseFloat(argv[0]);
            final ModelHyperbolicShell shell = new ModelHyperbolicShell(volume,station);
            System.out.printf("ModelHyperbolicShell(Sector % 2.2f, Area % 3.2f)%n",shell.sector,shell.area);
            float[] vertices = shell.vertices;

            float cx, cy, px = 0, py = 0, dx, dy;

            for (int cc = 0, count = vertices.length; cc < count; cc += 2){
                cx = vertices[cc+X];
                cy = vertices[cc+Y];

                if (0 == cc){
                    System.out.printf("% 3d % 2.2f,% 2.2f%n",((cc/2)+1),cx,cy);
                }
                else {
                    dx = (cx-px);
                    dy = (cy-py);
                    System.out.printf("% 3d % 2.2f,% 2.2f (% 2.2f,% 2.2f)%n",((cc/2)+1),cx,cy,dx,dy);
                }
                px = cx;
                py = cy;
            }
        }
        else {
            final float ds = (float)(volume.length/(Model.Top-1));
            
            for (float station = ds; station < volume.length; station += ds){
                ModelHyperbolicShell shell = new ModelHyperbolicShell(volume,station);

                System.out.printf("ModelHyperbolicShell(Sector % 2.2f, Area % 3.2f)%n",shell.sector,shell.area);
                float[] vertices = shell.vertices;
                for (int cc = 0, count = vertices.length; cc < count; ){

                    System.out.printf("% 3d % 2.2f,% 2.2f%n",((cc/2)+1),vertices[cc++],vertices[cc++]);
                }
            }
        }
    }
}
